package com.hong.qrpc.selector;

import com.hong.qrpc.TransportClient;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Random;

/**
 * @Author HQT
 * @Date 2022/7/10 16:45
 */
@Slf4j
@ToString
@EqualsAndHashCode
public class RandomTransportSelector extends AbstractTransportSelector {
    private Random random = new Random();

    /**
     * 随机选择一个网络传输客户端进行使用
     *
     * @return Net Client
     */
    @Override
    protected TransportClient select(ArrayList<TransportClient> clients) {
        int i = random.nextInt(clients.size());
        return clients.get(i);
    }
}
